-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Emitc.convert #136621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mtrofin
wants to merge
14
commits into
llvm:main
Choose a base branch
from
mtrofin:emitc.convert
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Emitc.convert #136621
+75
−10
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can test this locally with the following command:darker --check --diff -r HEAD~1...HEAD llvm/lib/Analysis/models/saved-model-to-tflite.pyView the diff from darker here.--- saved-model-to-tflite.py 2025-05-19 23:32:37.000000 +0000
+++ saved-model-to-tflite.py 2025-05-19 23:36:31.806946 +0000
@@ -30,11 +30,10 @@
json_file = "output_spec.json"
src_json = os.path.join(sm_dir, json_file)
if tf.io.gfile.exists(src_json):
tf.io.gfile.copy(src_json, os.path.join(tfl_dir, json_file))
tf.mlir.experimental.tflite_to_tosa_bytecode(
- tfl_path,
- os.path.join(tfl_dir, 'model.tosa')
+ tfl_path, os.path.join(tfl_dir, "model.tosa")
)
if __name__ == "__main__":
main(sys.argv)
|
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions cpp -- llvm/lib/ProfileData/PGOCtxProfReader.cpp mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp mlir/lib/Conversion/TosaToArith/TosaToArith.cpp mlir/lib/Conversion/TosaToArith/TosaToArithPass.cpp mlir/lib/Conversion/TosaToLinalg/TosaToLinalgPass.cpp mlir/lib/Target/Cpp/TranslateRegistration.cpp mlir/lib/Target/Cpp/TranslateToCpp.cppView the diff from clang-format here.diff --git a/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp b/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp
index 36b1fed29..5aadfab4e 100644
--- a/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp
+++ b/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp
@@ -223,6 +223,6 @@ void mlir::populateMemRefToEmitCTypeConversion(TypeConverter &typeConverter) {
void mlir::populateMemRefToEmitCConversionPatterns(
RewritePatternSet &patterns, const TypeConverter &converter) {
- patterns.add<ConvertAlloca, ConvertGlobal, ConvertGetGlobal,
- ConvertLoad, ConvertStore>(converter, patterns.getContext());
+ patterns.add<ConvertAlloca, ConvertGlobal, ConvertGetGlobal, ConvertLoad,
+ ConvertStore>(converter, patterns.getContext());
}
diff --git a/mlir/lib/Conversion/TosaToArith/TosaToArith.cpp b/mlir/lib/Conversion/TosaToArith/TosaToArith.cpp
index da4655e41..8261100b1 100644
--- a/mlir/lib/Conversion/TosaToArith/TosaToArith.cpp
+++ b/mlir/lib/Conversion/TosaToArith/TosaToArith.cpp
@@ -35,16 +35,16 @@ public:
};
class ConstShapeOpConverter : public OpRewritePattern<tosa::ConstShapeOp> {
- public:
- using OpRewritePattern<tosa::ConstShapeOp>::OpRewritePattern;
-
- LogicalResult matchAndRewrite(tosa::ConstShapeOp op,
- PatternRewriter &rewriter) const final {
- rewriter.replaceOpWithNewOp<shape::ConstShapeOp>(op, op.getValues());
- return success();
- }
- };
-
+public:
+ using OpRewritePattern<tosa::ConstShapeOp>::OpRewritePattern;
+
+ LogicalResult matchAndRewrite(tosa::ConstShapeOp op,
+ PatternRewriter &rewriter) const final {
+ rewriter.replaceOpWithNewOp<shape::ConstShapeOp>(op, op.getValues());
+ return success();
+ }
+};
+
Type matchContainerType(Type element, Type container) {
if (auto shapedTy = dyn_cast<ShapedType>(container))
return shapedTy.clone(element);
diff --git a/mlir/lib/Target/Cpp/TranslateRegistration.cpp b/mlir/lib/Target/Cpp/TranslateRegistration.cpp
index a6afa6ae2..9dd125db7 100644
--- a/mlir/lib/Target/Cpp/TranslateRegistration.cpp
+++ b/mlir/lib/Target/Cpp/TranslateRegistration.cpp
@@ -9,8 +9,8 @@
#include "mlir/Dialect/ControlFlow/IR/ControlFlow.h"
#include "mlir/Dialect/EmitC/IR/EmitC.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
-#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/Math/IR/Math.h"
+#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/Dialect.h"
#include "mlir/Target/Cpp/CppEmitter.h"
diff --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
index 1ed68a90f..aa5891c89 100644
--- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp
+++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
@@ -1145,10 +1145,10 @@ static LogicalResult printOperation(CppEmitter &emitter,
raw_indented_ostream &os = emitter.ostream();
os << "class MyClass final {\n";
auto argAttrs = functionOp.getArgAttrs();
-
+
std::map<std::string, Value> fields;
if (argAttrs)
- for (auto [a,v] : zip(*argAttrs, functionOp.getArguments())) {
+ for (auto [a, v] : zip(*argAttrs, functionOp.getArguments())) {
if (auto da = dyn_cast<mlir::DictionaryAttr>(a)) {
auto nv = da.getNamed("tf_saved_model.index_path")->getValue();
auto name = cast<mlir::StringAttr>(cast<mlir::ArrayAttr>(nv)[0]).str();
@@ -1160,27 +1160,29 @@ static LogicalResult printOperation(CppEmitter &emitter,
}
}
- for (auto & r : functionOp->getRegions())
+ for (auto &r : functionOp->getRegions())
for (auto &b : r.getBlocks())
for (auto &opt : b.getOperations())
if (auto alloc = dyn_cast<memref::AllocOp>(opt)) {
auto name = emitter.getOrCreateName(alloc).str();
fields[name] = alloc;
- if (failed(emitter.emitType(alloc.getLoc(), alloc.getType().getElementType())))
+ if (failed(emitter.emitType(alloc.getLoc(),
+ alloc.getType().getElementType())))
return failure();
- os << " [" << alloc.getType().getNumElements() <<"] ";
+ os << " [" << alloc.getType().getNumElements() << "] ";
os << " " << name << ";\n";
}
os << " std::map<std::string, char*> _buffer_map {";
- for (auto &[n,v]:fields)
- os << "{ \"" << n << "\"" << ", reinterpret_cast<char*>(" << emitter.getOrCreateName(v) << ") },";
+ for (auto &[n, v] : fields)
+ os << "{ \"" << n << "\"" << ", reinterpret_cast<char*>("
+ << emitter.getOrCreateName(v) << ") },";
os << " };\n";
os << " char* getBufferForName(const std::string& name) const {\n";
os << " auto it = _buffer_map.find(name);\n";
os << " return (it == _buffer_map.end()) ? nullptr : it->second;\n";
os << " }\n";
CppEmitter::Scope scope(emitter);
-
+
if (functionOp.getSpecifiers()) {
for (Attribute specifier : functionOp.getSpecifiersAttr()) {
os << cast<StringAttr>(specifier).str() << " ";
@@ -1201,7 +1203,8 @@ static LogicalResult printOperation(CppEmitter &emitter,
os << ");";
return success();
}
- // if (failed(printFunctionArgs(emitter, operation, functionOp.getArguments())))
+ // if (failed(printFunctionArgs(emitter, operation,
+ // functionOp.getArguments())))
// return failure();
os << ") {\n";
if (failed(printFunctionBody(emitter, operation, functionOp.getBlocks())))
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.